package com.example.renyang.happysell;

import android.content.Intent;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentActivity;
import android.support.v4.view.PagerAdapter;
import android.support.v4.view.ViewPager;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.ImageView;
import android.widget.RelativeLayout;

import com.example.renyang.happysell.MyAdapter.FragmentAdapter;

import java.util.ArrayList;
import java.util.List;

public class fragment_mall extends FragmentActivity implements View.OnClickListener{

    //初始化底部导航控件
    private RelativeLayout mTabmenu;
    private RelativeLayout mTaborder;
    private RelativeLayout mTabcart;
    private RelativeLayout mTabowner;

    //初始化导航控件中的图片
    private ImageView menu;
    private ImageView order;
    private ImageView cart;
    private ImageView owner;

    private ViewPager mViewPager;
    private PagerAdapter mAdapter;
    private List<Fragment> fragments=new ArrayList<Fragment>();


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.fragment_mall);

        initView();
        mViewPager=(ViewPager)findViewById(R.id.id_fragment);

        /**
         *   初始化Adapter
         */
        mAdapter=new FragmentAdapter(getSupportFragmentManager(),fragments);
        mViewPager.setAdapter(mAdapter);
    }


    public void initView(){

        mTabmenu=(RelativeLayout)findViewById(R.id.tab_menu);
        mTaborder=(RelativeLayout)findViewById(R.id.tab_order);
        mTabcart=(RelativeLayout)findViewById(R.id.tab_cart);
        mTabowner=(RelativeLayout)findViewById(R.id.tab_owner);

        menu=(ImageView)findViewById(R.id.imageV1);
        order=(ImageView)findViewById(R.id.imageV2);
        cart=(ImageView)findViewById(R.id.imageV3);
        owner=(ImageView)findViewById(R.id.imageV4);

        menu.setOnClickListener(new TabOnClickListener(0));
        order.setOnClickListener(new TabOnClickListener(1));
        cart.setOnClickListener(new TabOnClickListener(2));
        owner.setOnClickListener(new TabOnClickListener(3));

        fragments.add(new fragment_menu());
        fragments.add(new fragment_orderMan());
        fragments.add(new fragment_shopcart());
        fragments.add(new fragment_myInfo());

    }
    @Override
    public void onClick(View v) {
//        switch (v.getId()) {
//            case R.id.produce_manage_imageV:
//                Intent produceManIntent = new Intent(getApplicationContext(), ProduceManageActivity.class);
//                startActivity(produceManIntent);
//                break;
//            case R.id.order_manage_imageV:
//                Intent orderManIntent = new Intent(getApplicationContext(), Order_manageActivity.class);
//                startActivity(orderManIntent);
//                break;
//            case R.id.baobiao_manage_imageV:
//                Intent baobiaoManIntent = new Intent(getApplicationContext(), ProduceManageActivity.class);
//                startActivity(baobiaoManIntent);
//                break;
//        }
    }

    public class TabOnClickListener implements View.OnClickListener {

        private int index=0;
        @Override
        public void onClick(View v){
            mViewPager.setCurrentItem(index);
        }
        public TabOnClickListener(int i){
            index=i;
        }
    }
}
